//
//  SecondView.m
//  UI Demo
//
//  Created by Rainy Zou on 15/11/28.
//  Copyright © 2015年 Rainy Zou. All rights reserved.
//

#import "SecondView.h"

@implementation SecondView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    UIButton *btn = [[UIButton alloc]init];
    UIImage *imageNormal = [UIImage imageNamed:@"head_back_normal"];
    UIImage *imageSelected = [UIImage imageNamed:@"head_back_selected"];
    btn.contentEdgeInsets = UIEdgeInsetsMake(0, 8, 0, 0);
    [btn setBackgroundImage:imageNormal forState:UIControlStateNormal];
    [btn setBackgroundImage:imageSelected forState:UIControlStateHighlighted];
    
    NSString *back = @"返回";
    CGSize size = [back sizeWithAttributes:@{NSFontAttributeName:btn.titleLabel.font}];
    
    [btn setTitle:@"返回" forState:UIControlStateNormal];
    btn.titleLabel.textAlignment = NSTextAlignmentRight;
    
    [btn addTarget:self action:@selector(clickBack) forControlEvents:UIControlEventTouchUpInside];
    
    btn.bounds = CGRectMake(0, 0, size.width + 20 , 40);
    
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithCustomView:btn];
    
    
    self.navigationItem.leftBarButtonItem =leftItem;
    
}

-(void) clickBack
{
    [self.navigationController popViewControllerAnimated:YES];
}

@end
